package com.swdegao.iot.netty.server;

import com.swdegao.iot.netty.entity.Parameter;
import com.swdegao.iot.netty.server.channelhandler.HeartBeatClientHandler;
import com.swdegao.iot.netty.server.channelhandler.ParseMessgaeHandler;
import com.swdegao.iot.netty.server.channelhandler.PushMessgaeHandler;
import com.swdegao.iot.netty.server.channelhandler.SaveMessgaeHandler;
import com.swdegao.iot.netty.server.decoder.DG_DATADecoder_DB;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.timeout.IdleStateHandler;

import java.util.concurrent.TimeUnit;

public class NettyServerChannelInitializer extends ChannelInitializer<SocketChannel> {
	 private EventLoopGroup pusheventloop  = new NioEventLoopGroup();

    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {


    	socketChannel.pipeline().addLast(new IdleStateHandler(Parameter.heartbeat_cycle_check,0,0, TimeUnit.SECONDS));
    	socketChannel.pipeline().addLast(new DG_DATADecoder_DB(1<<20,1,2,-3,0));
    	socketChannel.pipeline().addLast(new HeartBeatClientHandler());
    	socketChannel.pipeline().addLast(new ParseMessgaeHandler());
    	socketChannel.pipeline().addLast(new SaveMessgaeHandler());
    	socketChannel.pipeline().addLast(pusheventloop,new PushMessgaeHandler());


    }
			}
